/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ChoixDeHorraire.java
 *
 * Created on 1 juin 2011, 14:46:33
 */

package cannes.gui;

import cannes.bean.planning.Film;
import cannes.bean.planning.Projection;
import cannes.dao.DAO;
import cannes.dao.DAOFactory;
import cannes.dao.implement.ProjectionDAO;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author p1008977
 */
public class ChoixDeHorraire extends javax.swing.JPanel {

    /** Creates new form ChoixDeHorraire */
    public ChoixDeHorraire(Projection proj) {
        initComponents();
        this.proj = proj;
        
        DAO<Film> filmDAO = DAOFactory.getFilmDAO();
        
        Film f = filmDAO.find(proj.getFilm());
        labelHoraire.setText(f.getTitre()+"  "+proj.getHorraire());
        textPaneDetails.setText(f.getResume());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labelHoraire = new javax.swing.JLabel();
        labelChoix = new javax.swing.JLabel();
        textFieldHeures = new javax.swing.JTextField();
        textFieldMinutes = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        buttonOk = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        textPaneDetails = new javax.swing.JTextPane();

        labelHoraire.setText("HH:MM Titre du film");

        labelChoix.setText("Choix horraire");

        textFieldHeures.setText("12");
        textFieldHeures.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textFieldHeuresActionPerformed(evt);
            }
        });
        textFieldHeures.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                textFieldHeuresKeyTyped(evt);
            }
        });

        textFieldMinutes.setText("00");
        textFieldMinutes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textFieldMinutesActionPerformed(evt);
            }
        });
        textFieldMinutes.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                textFieldMinutesKeyTyped(evt);
            }
        });

        jLabel1.setText("H");

        buttonOk.setText("Ok");
        buttonOk.setEnabled(false);
        buttonOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonOkActionPerformed(evt);
            }
        });

        textPaneDetails.setEditable(false);
        jScrollPane1.setViewportView(textPaneDetails);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 360, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(textFieldHeures, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textFieldMinutes, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(labelHoraire, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addComponent(labelChoix)
                    .addComponent(buttonOk, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelHoraire, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(labelChoix)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldHeures, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textFieldMinutes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(14, 14, 14)
                .addComponent(buttonOk)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void textFieldHeuresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textFieldHeuresActionPerformed

    }//GEN-LAST:event_textFieldHeuresActionPerformed

    private void buttonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonOkActionPerformed
        DAO<Projection> projDAO = DAOFactory.getProjectionDAO();
        Calendar c = Calendar.getInstance();
        c.setTime(proj.getHorraire());
        c.set(Calendar.HOUR, Integer.parseInt(textFieldHeures.getText()));
        c.set(Calendar.MINUTE, Integer.parseInt(textFieldMinutes.getText()));
        proj.setHorraire(c.getTime());
        proj.setId(projDAO.next());
        projDAO.create(proj);
        //TODO: trouver comment fermer la fenêtre
        this.setVisible(false);
    }//GEN-LAST:event_buttonOkActionPerformed

    private void textFieldMinutesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textFieldMinutesActionPerformed

    }//GEN-LAST:event_textFieldMinutesActionPerformed

    private void textFieldMinutesKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textFieldMinutesKeyTyped
        int heures = Integer.parseInt(textFieldHeures.getText());
        int minutes = Integer.parseInt(textFieldMinutes.getText());
        if(heures < 25 && heures > -1  && minutes > -1 && minutes < 61)
            buttonOk.setEnabled(true);
    }//GEN-LAST:event_textFieldMinutesKeyTyped

    private void textFieldHeuresKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textFieldHeuresKeyTyped
        int heures = Integer.parseInt(textFieldHeures.getText());
        int minutes = Integer.parseInt(textFieldMinutes.getText());
        if(heures < 25 && heures > -1  && minutes > -1 && minutes < 61)
            buttonOk.setEnabled(true);
    }//GEN-LAST:event_textFieldHeuresKeyTyped


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonOk;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labelChoix;
    private javax.swing.JLabel labelHoraire;
    private javax.swing.JTextField textFieldHeures;
    private javax.swing.JTextField textFieldMinutes;
    private javax.swing.JTextPane textPaneDetails;
    // End of variables declaration//GEN-END:variables

    Projection proj;
}
